<template>
    <h2>门店列表</h2>
    门店名称
    <input type="text" v-model="prist.sname">
    门店状态<select v-model="prist.state">
        <option value="">请选择</option>
        <option value="1">开店</option>
        <option value="0">关店</option>
    </select>
    <input type="button" value="查询" @click="getlist">
    <br><input type="button" value="录入房价" @click="tiaowkmws">
    <table>
        <tr>
            <td>门店名称</td>
            <td>门店图片</td>
            <td>门店地址</td>
            <td>创建时间</td>
            <td>状态</td>
            <td>操作</td>
        </tr>
        <tr v-for="item in list">
            <td>{{item.sname}}</td>
            <td><img :src="'https://localhost:7246'+item.spicture" width="60" height="60"></td>
            <td>{{item.saddress}}</td>
            <td>{{item.createtime.substr(0,10)}}</td>
            <td>{{item.states==1?"开店":"关店"}}</td>
            <td><input v-if="item.states==1" type="button" value="关店" @click="upsjnwkx(item.sid,item.states)"><input v-if="item.states==0" type="button" value="开店"  @click="upsjnwkx(item.sid,item.states)"><input type="button" value="修改" @click="updconsiwm(item.sid)"></td>
        </tr>
    </table>
    共<span style="color: red;">{{ count }}</span>条,每页<span style="color: red;">{{ prist.page }}</span>条,当前<span style="color: red;">{{ prist.index }}</span>/<span style="color: red;">{{ pcount }}</span>页
    
    <input type="button" value="首页" @click="setpage('a')">
    <input type="button" value="上一页" @click="setpage('b')">
    <input type="button" value="下一页" @click="setpage('c')">
    <input type="button" value="尾页" @click="setpage('d')">
  </template>
  
  <script setup lang="ts">
   import {onMounted, reactive, toRefs} from 'vue'
  import {useRouter,useRoute} from 'vue-router'
  import axios from 'axios'
  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    prist:{
        sname:'',
        state:'',
        index:1,
        page:2
    },
    count:0,
    pcount:0,
    list:[]
  })
  let {prist,count,pcount,list} =toRefs(data)

  onMounted(()=>{
    getlist()
  })

  const getlist=()=>{
    let obj={
        sname:prist.value.sname,
        states:prist.value.state,
        index:prist.value.index,
        page:prist.value.page
    }
    axios({
        url:'/api/Store/GetStores',
        method:'get',
        params:obj
    })
    .then(res=>{
        list.value=res.data.data;
        count=res.data.coco;
        pcount=res.data.promax;
    })
  }

  const setpage=(val:any)=>{
    switch(val){
        case "a":
            prist.value.index=1;
            ;break;
        case "b":
            prist.value.index--;
            ;break;
        case "c":
            prist.value.index++;
            ;break;
        case "d":
            prist.value.index=pcount;
            ;break;
    }
    getlist()
  }

  const upsjnwkx=(sid:any,states:any)=>{
    if(confirm("确定修改状态吗?")){
        if(states==1){
            states=0;
        }else{
            states=1;
        }
        let obj={
            sid:sid,
            states:states
        }
        axios({
            url:'/api/Store/Updstates',
            method:'get',
            params:obj
        })
        .then(res=>{
            if(res.data.data==1){
                alert("修改状态成功")
                getlist()
            }else{
                alert("修改状态失败")
            }
        })
    }
  }

  const updconsiwm=(sid:any)=>{
    router.push({
        path:'/updstore',
        query:{
            sid:sid
        }
    })
  }

  const tiaowkmws=()=>{
    router.push('addprice')
  }
  </script>
  
  <style scoped>
  
  </style>